﻿using AutoMapper;
using Fake_Shop_WebApi.Dtos;
using Fake_Shop_WebApi.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace Fake_Shop_WebApi.Controllers
{
    [ApiController]
    [Route("api/order")]
    public class OrderControllers:ControllerBase
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly ITouristRouteRepository _touristRouteRepository;
        private readonly IMapper _mapper;
        public OrderControllers(IHttpContextAccessor httpContextAccessor, ITouristRouteRepository touristRouteRepository
            , IMapper mapper)
        {
            _httpContextAccessor = httpContextAccessor;
            _touristRouteRepository = touristRouteRepository;
            _mapper = mapper;
        }
        [HttpGet]
        [Authorize(AuthenticationSchemes = "Bearer")]
        public async Task<IActionResult> GetOrder()
        {
            var UserId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var orders = await _touristRouteRepository.GetOrderAsync(UserId);

            return Ok(_mapper.Map<OrderDto>(orders));

        }
        [HttpPost("{orderId}")]
        [Authorize(AuthenticationSchemes = "Bearer")]
        public async Task<IActionResult> GetOrderById([FromRoute] Guid orderId)
        {
            var UserId = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var orders =  await _touristRouteRepository.GetOrderByIdAsync(orderId);
            return Ok(_mapper.Map<OrderDto>(orders));


        }
    }
}
